#include "driver_xxx_interface.h"
#include "stdio.h"
#include <cstdarg>

/**
 * @brief  interface iic bus init
 * @return status code
 *         - 0 success
 *         - 1 iic init failed
 * @note   none
 */
uint8_t xxx_interface_iic_init(void)
{
    MX_I2C1_Init();
    return 0;
}

/**
 * @brief  interface iic bus deinit
 * @return status code
 *         - 0 success
 *         - 1 iic deinit failed
 * @note   none
 */
uint8_t xxx_interface_iic_deinit(void)
{
    HAL_StatusTypeDef status;
    status = HAL_I2C_DeInit(&hi2c1);
    return status;
}

/**
 * @brief      interface iic bus read
 * @param[in]  addr iic device write address
 * @param[out] *buf pointer to a data buffer
 * @param[in]  len length of the data buffer
 * @return     status code
 *             - 0 success
 *             - 1 read failed
 * @note       none
 */
uint8_t xxx_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
{
    HAL_StatusTypeDef status;
    status = HAL_I2C_Master_Receive(&hi2c1, addr, buf, len, 1000);

    return status;
}

/**
 * @brief     interface delay ms
 * @param[in] ms time
 * @note      none
 */
void xxx_interface_delay_ms(uint32_t ms)
{
    HAL_Delay(ms);
}

/**
 * @brief     interface print format data
 * @param[in] fmt format data
 * @note      none
 */
void xxx_interface_debug_print(const char *const fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    vprintf(fmt, args);
    va_end(args);
}
